#coding=utf-8
from uliweb import expose
import generic.views as g_views

get_department_url = g_views.get_url('/config/department', restful=True)
layout = 'config_department_layout.html'

def __begin__():
    from uliweb import function
    return function('require_login')()

@expose('/config/department/list')
def config_department_list():
    return g_views.generic_list('depart', get_url=get_department_url, layout=layout, add_button_text='增加机构')

@expose('/config/department/add')
def config_department_add():
    return g_views.generic_add('depart', get_url=get_department_url, layout=layout, title='增加机构')

@expose('/config/department/<int:id>/edit')
def config_department_edit(id):
    if request.user.is_superuser:
        return g_views.generic_edit('depart', id, get_url=get_department_url, layout=layout, title='修改机构')
    else:
        flash('你不是超级用户或管理员，无法编辑此机构！')
        return redirect(url_for(config_department_list))

@expose('/config/department/<int:id>/delete')
def config_department_delete(id):
    if request.user.is_superuser:
        return g_views.generic_delete('depart', id, get_url=get_department_url)
    else:
        flash('你不是超级用户或管理员，无法删除此机构！')
        return redirect(url_for(config_department_list))

@expose('/config/department/<int:id>')
def config_department_view(id):
    return g_views.generic_view('depart', id, get_url=get_department_url, layout=layout, title='查看机构')
    
